*Til March 2021
import delimited using "HSSC replication data\Public data\OxCGRT_latest.csv.txt", clear

tostring date, gen(dates)
gen time=date(dates,"YMD")
gen year=year(time)
gen month=month(time)
tab month if year==2021

drop if year==2021 & month>=4

*Get regional pop weights
merge m:1 countryname regionname using  "HSSC replication data\Public data\region_weights.dta"
drop if _merge==2
drop _merge
replace region_weight=1 if region_weight==.
**Use aggregation of regions
tab countryname if regioncode!=""
drop if regioncode=="" & (countryname=="Canada" | countryname=="Brazil" | countryname=="United Kingdom" |  countryname=="United States")

tab regionname if countryname=="Canada"
tab regionname if countryname=="Brazil"
tab regionname if countryname=="United Kingdom"
tab regionname if countryname=="United States"

*shorten name
ren c7_restrictionsoninternalmovemen c7_restrictionsoninternal
ren h4_emergencyinvestmentinhealthca h4_emergency
ren c8_internationaltravelcontrols c8_internationaltravel
ren h1_publicinformation h1_publicinformation

*standardize
foreach x in c1_schoolclosing c2_workplaceclosing c3_cancelpublicevents c4_restrictionsongatherings c5_closepublictransport c6_stayathomerequirements c7_restrictionsoninternal c8_internationaltravel e1_incomesupport e2_debtcontractrelief e3_fiscalmeasures e4_internationalsupport h1_publicinformation h2_testingpolicy h3_contacttracing h4_emergency h5_investmentinvaccines h6_facialcoverings h7_vaccinationpolicy h8_protectionofelderlypeople  {
egen SD`x'=std(`x')
}

*categorical code
forval i=0/3 {
foreach x in c1_schoolclosing c2_workplaceclosing c4_restrictionsongatherings c6_stayathomerequirements {
gen `x'`i'=1 if `x'==`i'
replace `x'`i'=0 if `x'!=`i'
}
}

*binary code
foreach x in h6_facialcoverings h2_testingpolicy h3_contacttracing c1_schoolclosing c2_workplaceclosing c4_restrictionsongatherings c6_stayathomerequirements {
gen REQ`x'=1 if `x'==2 | `x'==3
replace REQ`x'=0 if `x'==0 | `x'==1
}

*alt index--used as unpublished robustness check
egen SHUT_DOWN=rowmean(SDc1_schoolclosing SDc2_workplaceclosing SDc4_restrictionsongatherings SDc6_stayathomerequirements)

collapse (first) countryname (mean) stringencyindex governmentresponseindex containmenthealthindex economicsupportindex ///
SHUT_DOWN  ///
SDc1_schoolclosing SDc2_workplaceclosing SDc3_cancelpublicevents SDc4_restrictionsongatherings SDc5_closepublictransport SDc6_stayathomerequirements SDc7_restrictionsoninternal SDc8_internationaltravel SDe1_incomesupport SDe2_debtcontractrelief SDe3_fiscalmeasures SDe4_internationalsupport SDh1_publicinformation SDh2_testingpolicy SDh3_contacttracing SDh4_emergency SDh5_investmentinvaccines SDh6_facialcoverings SDh7_vaccinationpolicy SDh8_protectionofelderlypeople ///
c1_schoolclosing c2_workplaceclosing c4_restrictionsongatherings c6_stayathomerequirements ///
REQh6_facialcoverings REQh2_testingpolicy REQh3_contacttracing REQc1_schoolclosing REQc2_workplaceclosing REQc4_restrictionsongatherings REQc6_stayathomerequirements ///
c1_schoolclosing0 c2_workplaceclosing0 c4_restrictionsongatherings0 c6_stayathomerequirements0 c1_schoolclosing1 c2_workplaceclosing1 c4_restrictionsongatherings1 c6_stayathomerequirements1 c1_schoolclosing2 c2_workplaceclosing2 c4_restrictionsongatherings2 c6_stayathomerequirements2 c1_schoolclosing3 c2_workplaceclosing3 c4_restrictionsongatherings3 c6_stayathomerequirements3 ///
[aw=region_weight], by(countrycode)

foreach x in stringencyindex governmentresponseindex containmenthealthindex economicsupportindex SHUT_DOWN ///
SDc1_schoolclosing SDc2_workplaceclosing SDc3_cancelpublicevents SDc4_restrictionsongatherings SDc5_closepublictransport SDc6_stayathomerequirements SDc7_restrictionsoninternal SDc8_internationaltravel SDe1_incomesupport SDe2_debtcontractrelief SDe3_fiscalmeasures SDe4_internationalsupport SDh1_publicinformation SDh2_testingpolicy SDh3_contacttracing SDh4_emergency SDh5_investmentinvaccines SDh6_facialcoverings SDh7_vaccinationpolicy SDh8_protectionofelderlypeople ///
 c1_schoolclosing c2_workplaceclosing c4_restrictionsongatherings c6_stayathomerequirements REQh6_facialcoverings REQh2_testingpolicy REQh3_contacttracing REQc1_schoolclosing REQc2_workplaceclosing REQc4_restrictionsongatherings REQc6_stayathomerequirements c1_schoolclosing0 c2_workplaceclosing0 c4_restrictionsongatherings0 c6_stayathomerequirements0 c1_schoolclosing1 c2_workplaceclosing1 c4_restrictionsongatherings1 c6_stayathomerequirements1 c1_schoolclosing2 c2_workplaceclosing2 c4_restrictionsongatherings2 c6_stayathomerequirements2 c1_schoolclosing3 c2_workplaceclosing3 c4_restrictionsongatherings3 c6_stayathomerequirements3 {
rename `x' C`x'
}

save "HSSC replication data\Public data\Oxford_Policy_Data_2020_to_March2021_Cumulative.dta", replace